/*main de testes */
package easyaccount;

import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import models.DbRequestsModel;
import models.*;

public class EasyAccount {

    public static void main( String[] args ) throws SQLException {
        
        String frase = "";
        DbRequestsModel teste =  new DbRequestsModel();
        /*passo 1 , conectar com banco*/
        Connection conexao = DriverManager.getConnection(
                "jdbc:mysql://localhost/bench", "root", "");

        System.out.println("Conectado!");

        /*passo 2 , criar um Statrment*/
        Statement action = conexao.createStatement();
        
        /*passo 3 , fazer um ResultSet para receber o Statement*/
        ResultSet result = action.executeQuery( "SELECT * FROM testdb;" );
        
        /*passo 4 , iterar no result*/
        while (result.next()) {
            frase += "nome : " + result.getString(1) + "| numero:" + result.getString(2) + "\n";
        }
        
        JOptionPane.showMessageDialog( null, frase );
        /*passo 5 , deletar do banco*/
        System.out.println( action.execute( "DELETE FROM testdb WHERE number=10;" ));
        
        /*passo 6 , fechar a conexão*/
        action.close();
        result.close();
        conexao.close();
        /*Teste com CRUD*/
        testeBD dataAction = new testeBD();
        Object resulte = (ResultSet)dataAction.listarTudo();
       while (result.next()) {
            frase += "nome : " + result.getString(1) + "| numero:" + result.getString(2) + "\n";
        }
        System.out.println(resulte.getClass());
        
       /* while (resulte.next()) {
            frase += "nome : " + result.getString(1) + "| numero:" + result.getString(2) + "\n";
            System.out.println(frase);
        }*/
     
        /*encerrar programa*/
        System.exit(0);    
    }
}
